package com.bangbang.service.impl;

import com.bangbang.pojo.TbCourse;
import com.bangbang.mapper.TbCourseMapper;
import com.bangbang.service.ITbCourseService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 课程商品表 服务实现类
 * </p>
 *
 * @author ${author}
 * @since 2021-08-11
 */
@Service
public class TbCourseServiceImpl extends ServiceImpl<TbCourseMapper, TbCourse> implements ITbCourseService {

    @Autowired
    private TbCourseMapper tbCourseMapper;

    @Autowired
    private RedisTemplate redisTemplate;

    @Override
    public List<TbCourse> selectRedis(Long uid) {
        List<TbCourse> courseList = (List<TbCourse>) redisTemplate.boundHashOps("courseList").get(uid);
        if(courseList == null){
            courseList = new ArrayList<>();
        }
        return courseList;
    }

    @Override
    public void saveRedis(Long uid,List<TbCourse> courseList1) {
        redisTemplate.boundHashOps("courseList").put(uid,courseList1);
    }

    @Override
    public List<TbCourse> selectGwc(Long id) {
        List<TbCourse> courseList = (List<TbCourse>)redisTemplate.boundHashOps("courseList").get(id);
        return courseList;
    }

    @Override
    public TbCourse selectById(Long couId) {
        TbCourse course = tbCourseMapper.selectAllId(couId);
        return course;
    }
}
